package com.mc.lp.shared.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
 * class to encrypt the password into md5 hash
 * @author deepak
 *
 */
public class MD5Encryptor implements IEncryptor {
	
	public String encrypt(String string)  {
		MessageDigest md=null;
		try {
			md = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			
		}
		assert(md!=null);
		md.update(string.getBytes());
		byte[] mdbytes = md.digest();
		 //convert the byte to hex format
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < mdbytes.length; i++) {
          sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
        }
		return sb.toString();
	}
	
	public static void main(String...strings ){
		System.out.println(new MD5Encryptor().encrypt("Admin@321"));
	}
}